import java.util.List;

public class Work01 {
    public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        //计算出链表里面存放的数字是多少
        StringBuilder s1 = new StringBuilder("") ,s2 = new StringBuilder("");
        while(l1 != null){
            s1.append(l1.val);
            l1 = l1.next;
        }
        while(l2 != null){
            s2.append(l2.val);
            l2 = l2.next;
        }
        String num1 = s1.toString();
        String num2 = s2.toString();
        int a = Integer.parseInt(num1);
        int b  = Integer.parseInt(num2);
        int c = a + b;
        ListNode res = new ListNode();
        //先用一个带头节点的单链表将其串起来 然后再将单链表逆置
        while(c!= 0){
            ListNode newNode = new ListNode(c % 10);
            newNode.next = res.next;
            res.next = newNode;
            c = c/10;
        }
        return res;
    }


    public static void main(String[] args) {
        ListNode l1 = new ListNode(2);
        l1.next = new ListNode(4);
        l1.next.next = new ListNode(9);
        ListNode l2 = new ListNode(5);
        l2.next = new ListNode(6);
        l2.next.next = new ListNode(4);
        l2.next.next.next = new ListNode(9);
        ListNode listNode = addTwoNumbers(l1, l2);
    }
}

